package demon3;

import java.lang.constant.Constable;
class Money implements Cloneable{
    public double money=12.2;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
    @Override
    public String toString() {
        return "Money{" +
                "money=" + money +
                '}';
    }
}
class Student implements Cloneable{
    public int age;
    public Money m=new Money();
    public Student(int age){
        this.age=age;
    }
    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
        Student tmp=(Student) super.clone();
        tmp.m=(Money) this.m.clone();
        return tmp;
    }
}
public class Test {
    public static void main(String[] args)throws CloneNotSupportedException {
        Student student1= new Student(10);
        Student student2=(Student) student1.clone();  //这里把一个父类给子类需要强转。


        System.out.println(student2);
        System.out.println(student1.m.money);
        System.out.println(student2.m.money);
        System.out.println("===========");
        student1.m.money=110;
//        student2.m.money=
        System.out.println(student1.m.money);
        System.out.println(student2.m.money);

    }
}